package org.lightmtv.request;

import java.util.Map;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.lightcommons.util.ConvertUtils;

public class RequestBean extends AbstractRequest{

	private String method;
	private String path;
	private Map<String, FileUpload> uploads;
	private Map<String, String> params;
	private Map<String, String> headers;
	private String contextPath;
	private Cookie[] cookies;
	private HttpSession session;
	
	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public Map<String, String> getParams() {
		return params;
	}

	public void setParams(Map<String, String> params) {
		this.params = params;
	}

	public Map<String, FileUpload> getUploads() {
		return uploads;
	}

	public void setUploads(Map<String, FileUpload> uploads) {
		this.uploads = uploads;
	}
	
	public String getParam(String name) {
		return getParams().get(name);
	}
	
	public <T> T getParam(String name, Class<T> toClass) {
		return ConvertUtils.convert(getParam(name), toClass);
	}
	
	@SuppressWarnings("unchecked")
	public <T> T getParam(String name, T defaultValue) {
		T ret = (T) getParam(name, defaultValue.getClass());
		if(ret ==null)
			return defaultValue;
		return ret;
	}

	public String getContextPath() {
		return contextPath;
	}

	public void setContextPath(String contextPath) {
		this.contextPath = contextPath;
	}

	public Map<String, String> getHeaders() {
		return headers;
	}

	public void setHeaders(Map<String, String> headers) {
		this.headers = headers;
	}

	public Cookie[] getCookies() {
		return cookies;
	}

	public void setCookies(Cookie[] cookies) {
		this.cookies = cookies;
	}

	public HttpSession getSession() {
		return session;
	}

	public void setSession(HttpSession session) {
		this.session = session;
	}

	@Deprecated
	public HttpServletRequest getServletRequest() {
		return null;
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}
	
}
